package fileIO;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class XLSWriter {
	/**
	 * Writes a workbook to an output directory
	 * @param wkb Workbook to be written
	 * @param outputFile output file to be written to
	 * @return write successful
	 */
	public static File write(HSSFWorkbook wkb, String outputFile){
		
		try {
			File fileOut = new File(outputFile);
			if(fileOut.exists()){
				//show overwrite dialog
			}else{
				fileOut.createNewFile();
			}
			FileOutputStream outputStream = new FileOutputStream(outputFile);
			wkb.write(outputStream);
			wkb = null;
			outputStream.flush();
			outputStream.close();
			return fileOut;
		} catch (FileNotFoundException e) {
			return null;
		} catch (IOException e) {
			return null;
		}
		
	}
}
